#include <iostream>
#include "Bhand.h"

using namespace std;

//**********************************************************************************
Hand::Hand(){
	
	index = 0;
	size = 7;
	value = 0;
	
	for(int i = 0;i <7;i++)
	        changeAce[i]= false;
	
}

Hand::Hand(int Hsize){
	size = Hsize;
    index = 0;
    value = 0;
}

//**********************************************************************************
void Hand::displayHand(){
	for (int i = 0; i < index; i++)
		cout << " -------- ";
	cout << endl;
	
	for (int j = 0; j < index; j++)
		cout << "|" << hand[j] << "      |";
	cout << endl;
	
	for (int k = 0; k < 7; k++){
		for (int l = 0; l < index; l++){
			cout << "|        |";
		}
	cout << endl;
	}
	
	for (int m = 0; m < index; m++)
		cout << "|      " << hand[m] << "|";
	cout << endl;

	for (int n = 0; n < index; n++)
		cout << " -------- ";
	cout << endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
void Hand::displayH_Hand(){
     for (int i = 0; i < index; i++)
		cout << " -------- ";
	cout << endl;
	
	for (int j = 0; j < index; j++){
        if(j == 0)
		     cout << "|" <<"        |";
        if(j > 0)
            cout << "|" << hand[j] << "      |";
    }
	cout<<endl;
	for (int k = 0; k < 7; k++){
		for (int l = 0; l < index; l++){
		
            if(k < 3)
               	cout << "|        |";
            if(k == 3)
                if(l == 0)
                     cout<<"|  Hole  |";
                else
                     cout<<"|        |";
            if(k > 3)
                cout << "|        |";
			
	
        	
         }
         cout << endl;
	}
	
	for (int m = 0; m < index; m++){
		if(m == 0)
		     cout << "|" <<"        |";
        if(m > 0)
            cout << "|      " << hand[m] << "|";
    }
    cout<<endl;

	for (int n = 0; n < index; n++)
		cout << " -------- ";
	cout << endl;
}
     
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
ostream& operator<<(ostream& out, Hand myHand) {
	for (int i = 0; i < myHand.index; i++)
		out << " -------- ";
	out << endl;
	
	for (int j = 0; j < myHand.index; j++)
		out << "|" << myHand.hand[j] << "      |";
	out << endl;
	
	for (int k = 0; k < 7; k++){
		for (int l = 0; l < myHand.index; l++){
			out << "|        |";
		}
	out << endl;
	}
	
	for (int m = 0; m < myHand.index; m++)
		out << "|      " << myHand.hand[m] << "|";
	out << endl;

	for (int n = 0; n < myHand.index; n++)
		out << " -------- ";
	out << endl;

	return out;
	
}

//**********************************************************************************
void Hand::addCard(Card card){
	hand[index] = card;
	int count;
	
	if(card.getVal() >= 2 && card.getVal() <= 9)
         value += card.getVal();
    else if(card.getVal() >= 10 && card.getVal() <= 13)
         value += 10;
    else{
         if(value + 11 <= 21)
                  value += 11;
         else{
                  value += 1;
                  changeAce[index+1] = true;
         }
    }
    index++;
    //this is for a natural win
    if(index == 2 && value == 21)
             value += 1;
             
   else {
        for( int i = 0; i < 7; i++)
            Aces(i);          
   }
}

//**********************************************************************************
bool Hand::isEmpty(){
	if(index == 0)
		return true;
	else
		return false;
}

//**********************************************************************************
bool Hand::isFull(){
	if(index == size)
		return true;
	else
		return false;
}
//***********************************************************************************

void Hand::Aces(int i){
                  
                    
          if(hand[i].getVal()  == 14 && changeAce[i] == false && value > 21){
                               changeAce[i] = true;
                               value -= 10;
          }
}

     

